<div class="order-filter">
  <form action="<?php echo url('user/order_list') ?>" method="post" id="form_order">
    <ul>
      <li>
        <span><?php echo L('orderstatus');?>：</span>
        <div class="select-widget">
          <i></i>
          <span id="order_status_name"><?php echo $order_result['name'];?></span>
          <select name="order_status" id="order_status" >
            <option value="" <?php if("" == $order_result['osid'])echo 'selected';?> ><?php echo L('any')?></option>
            <?php foreach (OrderModel::$orderStatus as $key => $val): if($key == 0) $key = 100;?>
            <option value="<?php echo $key;?>" <?php if($key == $order_result['osid'])echo 'selected';?>><?php echo L($val);?></option>
            <?php endforeach;?>
          </select>
        </div>
      </li>
      <li>
        <span><?php echo L('paystatus');?>：</span>
        <div class="select-widget">
          <i></i>
          <span id="payment_status_name"><?php echo $payment_result['name'];?></span>
          <select name="payment_status" id="payment_status" >
            <option value="" <?php if("" == $payment_result['psid'])echo 'selected';?> ><?php echo L('any')?></option>
            <?php foreach (OrderModel::$paymentStatus as $key => $val): if($key == 0) $key = 100;?>
            <option value="<?php echo $key;?>" <?php if($key == $payment_result['psid'])echo 'selected';?>><?php echo L($val);?></option>
            <?php endforeach;?>
          </select>
        </div>
      </li>
      <li class="search-order">
        <input type="text" name="order_sn" value="<?php echo $order_sn;?>">
        <button type="submit"></button>
      </li>
    </ul>
  </form>
</div>
<table class="table-list">
  <tr>
    <th width="20%"><?php echo L('ordersn');?></th>
    <th width="13%"><?php echo L('goods_total');?></th>
    <th width="13%"><?php echo L('paid_amount');?></th>
    <th width="34%"><?php echo L('recharge_status');?></th>
    <th width="20%"><?php echo L('_ACTION_');?></th>
  </tr>
  <?php foreach ($ordersList as $k => $order) : ?>
  <?php if($order['order_status'] != -2):?>
  <tr>
    <td><a href="<?php echo url('user/order_info', 'oid='.$order['id']);?>" class="link-gray"><?php echo isset($order['order_sn'])? $order['order_sn'] : null;?></a></td>
    <td><?php echo isset($order['order_amount']) ? currency($order['order_amount']) : null; ?></td>
    <td><?php echo isset($order['pay_amount']) ? currency($order['pay_amount']) : null; ?></td>
    <td><?php echo L(OrderModel::$orderStatus[$order['order_status']]);?> / <?php if($order['return_status']){ echo $order['return_status'];}else{echo L(OrderModel::$paymentStatus[$order['payment_status']]);}?> / <?php echo L(OrderModel::$shippingStatus[$order['shipping_status']]);?>
      <?php
      if($order['shipping_status'] == OrderModel::SHIPPING_UNSHIPPED){
      $orderslogs = array();
      $orderslogs = M('orders_log')->where(array('order_id' => $order['id']))->order('id DESC')->select();
        if($orderslogs){
            foreach($orderslogs as $kkk => $vvv){
                if($vvv['shipping_status'] == 99){
                    echo '/ '.L('_PROCESSING_');
                    break;
                }
            }
        }
      }
      ?>
    </td>
    <td class="action">
      <a href="<?php echo url('user/order_info', 'oid='.$order['id']);?>"><?php echo L('orderdetailed')?></a>
      <?php if($order['order_status'] == OrderModel::ORDER_COMPLETE):?>
      <a href="<?php echo url('user/comment_add', 'oid='.$order['id']);?>">
        <?php if($order['add_comment']):?>
          <?php echo L('addproductscomment')?>
        <?php else:?>
          <?php echo L('productscomment')?>
        <?php endif;?>
      </a>
      <?php endif;?>
      <?php if($order['order_status'] == OrderModel::ORDER_UNCONFIRMED && $order['payment_status'] == OrderModel::PAY_UNPAYED) : ?>
	    <span title="<?php echo L('order_cancel');?>" data-order-id="<?php echo $order['id'];?>" data-cancel-order-tip="<?php echo L('cancel_order_tip');?>" class="green cur-pointer js-cancel-order"><?php echo L('order_cancel');?></span>
      <?php endif; ?>
      <?php if($order['order_status'] == OrderModel::ORDER_UNCONFIRMED && $order['payment_status'] == OrderModel::PAY_UNPAYED) : echo isset($order['paymentSubmit']) ? $order['paymentSubmit'] : null; endif; ?>
    </td>
  </tr>
  <?php endif;?>
  <?php endforeach;?>
</table>
<div class="align-right paging"><?php echo $pageShow;?></div>
<div class="js-order-cancel-cont" hidden>
  <div class="auto cancel-cont">
    <h3 class="align-center normal"><?php echo L('order_cancel');?></h3>
    <ul>
      <li><label><input type="radio" name="canceltype" value="1"><?php echo L('Cancel_Order_1');?></label></li>
      <li><label><input type="radio" name="canceltype" value="2"><?php echo L('Cancel_Order_2');?></label></li>
      <li><label><input type="radio" name="canceltype" value="3"><?php echo L('Cancel_Order_3');?></label></li>
      <li><label><input type="radio" name="canceltype" value="4"><?php echo L('Cancel_Order_4');?></label></li>
      <li><?php echo L('Cancel_Order_Others');?><textarea></textarea></li>
    </ul>
  </div>
</div>

<script src="/statics/front/js/plugins/jquery.popupBox.js"></script>
<script>
$(function () {
  (function () {
    function orderSearch() {//订单筛选
      var osid = $('#order_status').val(),
        psid = $('#payment_status').val();
      window.location.href = '/user/order_list/order_status/' + osid + '/payment_status/' + psid;
    }

    $('#order_status').on('change', function () {
      orderSearch();
    });

    $('#payment_status').on('change', function () {
      orderSearch();
    });
  }());

  $('.js-cancel-order').popupBox({
    quickClose: true,
    button: ["<?php echo L('yes');?>", "<?php echo L('no');?>"],
    content: $(".js-order-cancel-cont").html() + "<h3 class='align-center normal'><?php echo L('order_cancel_confirm')?></h3>",
    beforeShow: function (trigger, popupBox) {
      popupBox.addClass('order-cancellation');
    },
    afterShow: function (trigger, popupBox) {
      popupBox.on('click', 'input[type=radio]', function () {
        popupBox.find('textarea').val('').end().find('.js-error').remove();
      });
      popupBox.on('click', 'textarea', function () {
        popupBox.find('input[type=radio]').prop('checked', false).end().find('.js-error').remove();
      });
    },
    onOk: function (trigger, popupBox) {
      var orderId = trigger.data('orderId'),
          canceltype = popupBox.find('input[type=radio]').filter(':checked').val();
          message = popupBox.find('textarea').val(),
          empty = /^\s*$/,
          str = '';

      if (!canceltype && empty.test(message)) {
        popupBox.find('.js-popup-bd').append('<p class="align-center error js-error">' + trigger.data('cancelOrderTip') + '</p>');
        return false;
      }

      if (canceltype) {
        str = '/canceltype/' + canceltype;
      } else if (!empty.test(message)) {
        str = '/message/' + encodeURI(message);
      }

      window.location.href = url('user/order_cancel/oid/' + orderId + str);
    }
  });
});
</script>